package com;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.security.authentication.AuthenticationProvider;
import org.springframework.security.authentication.BadCredentialsException;
import org.springframework.security.authentication.RememberMeAuthenticationToken;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.AuthenticationException;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.web.authentication.WebAuthenticationDetails;
import org.springframework.stereotype.Component;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;

/**
 * Created by sola on 2018/1/30.
 */
@Component
public class MyAuthenticationProvider implements AuthenticationProvider {

    private HttpServletRequest httpServletRequest;

    private StringRedisTemplate stringRedisTemplate;

    @Autowired
    public MyAuthenticationProvider(HttpServletRequest httpServletRequest, StringRedisTemplate stringRedisTemplate) {
        this.httpServletRequest = httpServletRequest;
        this.stringRedisTemplate = stringRedisTemplate;
    }

    @Override
    public Authentication authenticate(Authentication authentication) throws AuthenticationException {
        WebAuthenticationDetails details=(WebAuthenticationDetails)authentication.getDetails();
        String sessionId=details.getSessionId();
        String sessionId2=stringRedisTemplate.opsForValue().get(sessionId);
        String s=stringRedisTemplate.opsForValue().get("98615E440ED03AB27B72056F1C76869E");

        return authentication;
    }

    @Override
    public boolean supports(Class<?> aClass) {
        return true;
    }
}
